From 3825ccccccd09f7ea0ca46eaa0210a39c99e96f8 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 2 Jun 2016 11:37:32 -0700 Subject: [PATCH] Correctly record multiple native dirs per package This fixes a bug when a package's build script outputs multiple library search paths. Because Compilation::native_dirs is a `HashMap` it can only store one path per package. Currently if there are multiple paths, all but the last will be inserted and then overwritten. The key from this map is never used anyway, so this fixes the bug by changing it from a HashMap to a HashSet. --- src/cargo/ops/cargo_rustc/compilation.rs | 6 +++--- src/cargo/ops/cargo_rustc/mod.rs | 2 +- src/cargo/ops/cargo_test.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index f5fd87dde..45c0e495b 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -27,7 +27,7 @@ pub struct Compilation<'cfg> { /// This is currently used to drive some entries which are added to the /// LD_LIBRARY_PATH as appropriate. // TODO: deprecated, remove - pub native_dirs: HashMap, + pub native_dirs: HashSet, /// Root output directory (for the local package's artifacts) pub root_output: PathBuf, @@ -51,7 +51,7 @@ impl<'cfg> Compilation<'cfg> { pub fn new(config: &'cfg Config) -> Compilation<'cfg> { Compilation { libraries: HashMap::new(), - native_dirs: HashMap::new(), // TODO: deprecated, remove + native_dirs: HashSet::new(), // TODO: deprecated, remove root_output: PathBuf::from("/"), deps_output: PathBuf::from("/"), tests: Vec::new(), @@ -94,7 +94,7 @@ impl<'cfg> Compilation<'cfg> { pub fn process(&self, cmd: CommandType, pkg: &Package) -> CargoResult { let mut search_path = util::dylib_path(); - for dir in self.native_dirs.values() { + for dir in self.native_dirs.iter() { search_path.push(dir.clone()); } search_path.push(self.root_output.clone()); diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index c7c6e6252..9bf42a851 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -161,7 +161,7 @@ pub fn compile_targets<'a, 'cfg: 'a>(pkg_targets: &'a PackagesToBuild<'a>, cx.compilation.cfgs.extend(output.cfgs.iter().cloned()); } for dir in output.library_paths.iter() { - cx.compilation.native_dirs.insert(pkg.clone(), dir.clone()); + cx.compilation.native_dirs.insert(dir.clone()); } } Ok(cx.compilation) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 42e365f6a..9c0bc25e1 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -140,7 +140,7 @@ fn run_doc_tests(options: &TestOptions, arg.push(rust_dep); p.arg("-L").arg(arg); } - for native_dep in compilation.native_dirs.values() { + for native_dep in compilation.native_dirs.iter() { p.arg("-L").arg(native_dep); } -- 2.30.2